// $Id: io_w.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <sstream>
#include <boost/test/unit_test.hpp>
#include <xpcom/result.hpp>
#include <xpcom/result_code.hpp>
#include <xpcom/string.hpp>

#ifdef XPCOM_HAS_2BYTE_WCHAR_T
#ifndef BOOST_NO_STD_WSTRING

BOOST_AUTO_TEST_CASE(test_extract_w)
{
    using namespace xpcom;

    result r1, r2, r3;

    std::wstringstream s1(L"  123      456 ");
    s1 >> r1 >> r2;
    BOOST_CHECK(r1 == 123);
    BOOST_CHECK(r2 == 456);

    std::wstringstream s2(L"  123      0x456 ");
    s2 >> std::hex >> r1 >> r2;
    BOOST_CHECK(r1 == 0x123);
    BOOST_CHECK(r2 == 0x456);

    std::wstringstream s3(L"  ae23 ");
    s3 >> r1;
    BOOST_CHECK(!s3);
}

BOOST_AUTO_TEST_CASE(test_insert_w)
{
    using namespace xpcom;

    result r1 = NS_ERROR_OUT_OF_MEMORY;

    std::wstringstream s;
    s << r1;
    BOOST_CHECK(s);
    BOOST_CHECK(s.str() == L"0x8007000E");
}

#endif
#endif
